home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Linux
/
Kubuntu 8.10
/
kubuntu-8.10-desktop-i386.iso
/
casper
/
filesystem.squashfs
/
usr
/
share
/
acpi-support
/
state-funcs
< prev
next >
Wrap
Text File
|
2008-10-14
|
3KB
|
110 lines
#!/bin/sh
# Paul Sladen, 2006-03-28, 2007-03-26
# Library functions to check/change status of wireless
# Return 0 if there is, allowing you to write if isAnyWirelessPoweredOn; then ...
isAnyWirelessPoweredOn()
{
for DEVICE in /sys/class/net/* ; do
if [ -d $DEVICE/wireless ]; then
# Hurray for stable interfaces... now the rfkill is scarcely
# associated with the network device at all (!)
for RFKILL in $DEVICE/device/rfkill/rfkill*/state; do
if [ -r "$RFKILL" ] && [ "$(cat "$RFKILL")" -eq 1 ]
then
return 0
fi
done
# if any of the wireless devices are turned on then return success
if [ -r $DEVICE/device/power/state ] && [ "`cat $DEVICE/device/power/state`" -eq 0 ]
then
return 0
fi
if [ -r $DEVICE/device/rf_kill ] && [ "`cat $DEVICE/device/rf_kill`" -eq 0 ]
then
return 0
fi
fi
done
# otherwise return failure
return 1
}
# Takes no parameters, toggles all wireless devices.
# TODO: Should possible toggle all wireless devices to the state of the first one.
# Attempts to use 'rf_kill' first, and then tries 'power/state', though that
# will fail on >=2.6.18 kernels since upstream removed the functionality...
toggleAllWirelessStates()
{
for DEVICE in /sys/class/net/* ; do
if [ -d $DEVICE/wireless ] ; then
# $DEVICE is a wireless device.
FOUND=
# Yes, that's right... the new interface reverses the truth values.
ON=1
OFF=0
for CONTROL in $DEVICE/device/rfkill/rfkill*/state; do
if [ -w "$CONTROL" ]; then
FOUND=1
if [ "$(cat "$CONTROL")" = "$ON" ] ; then
# It's powered on. Switch it off.
echo -n "$OFF" > "$CONTROL"
else
# It's powered off. Switch it on.
echo -n "$ON" > "$CONTROL"
fi
fi
done
# it might be safe to assume that a device only supports one
# interface at a time; but just in case, we short-circuit
# here to avoid toggling the power twice
if [ -n "$FOUND" ]; then
continue
fi
ON=0
OFF=1 # 1 for rf_kill, 2 for power/state
for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do
if [ -w $CONTROL ] ; then
# We have a way of controlling the device, lets try
if [ "`cat $CONTROL`" = 0 ] ; then
# It's powered on. Switch it off.
if echo -n $OFF > $CONTROL ; then
break
else
OFF=2 # for power/state, second time around
fi
else
# It's powered off. Switch it on.
if echo -n $ON > $CONTROL ; then
break
fi
fi
fi
done
fi
done
}
# Pass '1' to blink suspending LED and '0' to stop LED
setLEDThinkpadSuspending()
{
action=`test "$1" -ne 0 && echo blink || echo off`
test -w /proc/acpi/ibm/led && echo -n 7 "$action" > /proc/acpi/ibm/led
}
# Pass '1' to light LED and '0' to dark LED
setLEDAsusWireless()
{
action=`test "$1" -ne 0 && echo 1 || echo 0`
# (Older) asus-acpi module
test -w /proc/acpi/asus/wled && echo -n "$action" > /proc/acpi/asus/wled
# (Newer) asus-laptop module
test -w /sys/devices/platform/asus-laptop/wlan && echo -n "$action" > /sys/devices/platform/asus-laptop/wlan
}